package com.deng.dubbo.consumer.service.imp;

import com.alibaba.dubbo.config.annotation.Reference;
import com.deng.dubbo.consumer.service.IOrderService;
import com.deng.dubbo.library.IUserService;
import com.deng.dubbo.library.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
 * @Author DengLibin
 * @Date 19-5-15
 * @Time 下午8:24
 * @Desc
 */
@Service
public class OrderServiceImpl implements IOrderService {
    //服务提供者指定了版本,这里也要指定
    //url: 直接连服务 绕过zookeeper
    //stu: 本地根存
   @Reference(version = "1.0", check = false, // url = "192.168.0.102:20880",
           stub = "com.deng.dubbo.consumer.service.imp.UserServiceStub")
    private IUserService userService;
    @PostConstruct
    public  void  init(){
        showOrder();
    }
    @HystrixCommand(fallbackMethod = "errorNow")
    @Override
    public void showOrder() {
        if(userService == null){
            System.out.println("userService为空");
            return;
        }
       User user = userService.getById(1);
       if(user != null){
           System.out.println(user.getName());
       }else{
           System.out.println("无任何返回");
       }

    }

    public void errorNow() {
        System.out.println("服务调用出错了");
    }
}
